<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Netty WebSocket时间服务器</title>
</head>
<body>
<script>
    var socket;

    if (!window.WebSocket) {
        window.WebSocket = window.MozWebSocket;
    }

    if (window.WebSocket) {
        socket = new WebSocket("ws://127.0.0.1:10025/websocket");

        socket.onmessage = function (ev) {
            var ta = document.getElementById("responseText");
            ta.value = "";
            ta.value = ev.data;
        };

        socket.onopen = function (ev) {
            var ta = document.getElementById("responseText");

            ta.value = "打开WebSocket服务正常，浏览器支持WebSocket!";
        };

        socket.onclose = function (ev) {
            var ta = document.getElementById("responseText");

            ta.value = "";

            ta.value = "WebSocket 关闭！";
        };
    } else {
        alert("抱歉，你的浏览器不支持WebSocket协议");
    }

    function sendMsg() {
        msg = document.getElementById("message").value

        if (!window.WebSocket) {
            return;
        }

        if (socket.readyState == WebSocket.OPEN) {
            socket.send(msg);
        } else {
            alert("WebSocket 没有建立成功！");
        }
    }
</script>

<form onsubmit="return false">
    <input type="text" id="message" value="Netty">
    <br>
    <input type="button" value="Send" onclick="sendMsg();">
    <hr color="blue"/>
    <h3>Response</h3>
    <textarea id="responseText" style="width: 500px;height: 300px;"></textarea>
</form>
</body>
</html>